package com.speedchina.oauth2_permission;

import com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DynamicDataSourceAutoConfiguration;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author Administrator
 */
@EnableSwagger2
@EnableTransactionManagement
@ComponentScan(basePackages = {"com.speedchina"})
@MapperScan({"com.speedchina.permission.dao"})
//@SpringBootApplication(exclude = DynamicDataSourceAutoConfiguration.class)
@SpringBootApplication
public class Oauth2Application {

    public static void main(String[] args) {
        SpringApplication.run(Oauth2Application.class, args);
    }

    public void switchDataSource(){
        // https://www.cnblogs.com/drott/p/14596514.html
        // holder中队列中新曾一个数据源标识，可以切换数据源
        DynamicDataSourceContextHolder.push("master");
        // 切换后执行sql
//        List<Dict> list = dictMapper.list(dictType);
        // 执行完后进行释放
        DynamicDataSourceContextHolder.poll();
    }
}